﻿using AutoStar.Common;
using AutoStar.Properties;
using AutoStar.ViewModel;
using AutoStar.Views;
using AutoStar.Views.Pages;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace AutoStar
{
    /// <summary>
    /// 全局静态类
    /// </summary>
    public static class Global
    {
        public static CurrentProjectVM CurrentProjectVM { get; set; }
        public static WindowCommandHistoryVM HistoryVM { get; set; }
        public static MainViewVM MainViewVM { get; set; }
        public static MainWindowVM MainVM { get; set; }
        public static PrintChannelVM PrintChannelVM { get; set; }
        public static PrintSliceVM SliceVM { get; set; }
        public static PrintSliceView SliceView { get; set; }
        public static WindowSerialVM serialVM { get; set; }
        public static PrintStatusVM printStatusVM { get; set; }
        public static WindowOtherVM WindowOtherVM { get; set; }
        public static WindowXYZVM WindowXYZVM { get; set; }
        public static WindowXYZ WindowXYZ { get; set; }
        public static SliceParaVM SliceParaVM { get; set; }
        public static WindowLoginVM WindowLoginVM { get; set; }
        public static WindowMonitorVM WindowMonitorVM { get; set; }
        public static WindowMonitor Monitor { get; set; }
        public static PrintLayer printLayer { get; set; }
        public static Printer printer { get; set; }
        public static PrintProject printProject { get; set; }
        public static WindowSerial WindowSerial { get; set; }
        public static WindowSlice WindowSlice { get; set; }
        public static WindowLayer WindowLayer { get; set; }
        public static WindowLayerVM layerVM { get; set; }
        public static Encryption encryption { get; set; }
        public static WindowImportGCode WindowImportGCode { get; set; }
        public static WindowImportGCodeVM gCodeVM { get; set; }
        public static PrintParaVM printParaVM{ get; set; }
        public static SettingViewVM SettingVM { get; set; }
        public static List<Line3D> lines = new List<Line3D>();//用于在状态监测界面画路径的线
        public static Configuration config;
        public static AppSettingsSection settings;
        public static SettingView SettingView { get; set; }
        public static LogHelper LogHelper { get; set; }
        public static List<Point3D> StopPrintPoints { get; set; } = new List<Point3D>();//用于存储停止打印的点坐标
        public static UploadInfo UploadInfo { get; set; } = new UploadInfo();
        static Global()
        {
            try
            {
                encryption = new Encryption();
                config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                settings = config.AppSettings;
                WindowLoginVM = new WindowLoginVM();
                MainVM = new MainWindowVM();
                MainViewVM = new MainViewVM();
                SliceView = new PrintSliceView();
                SliceVM = new PrintSliceVM();
                serialVM = new WindowSerialVM();
                printLayer = new PrintLayer();
                layerVM = new WindowLayerVM();
                printer = Printer.GetPrinter(150, 130, 100);
                printProject = new PrintProject();
                printStatusVM = new PrintStatusVM();
                WindowSerial = new WindowSerial();
                CurrentProjectVM = new CurrentProjectVM();
                //PrintChannelVM = new PrintChannelVM();
                SettingVM = new SettingViewVM();
                SettingView = new SettingView();
                PrintChannelVM = new PrintChannelVM(Global.SettingVM._lowTemperatureModule);
                WindowXYZVM = new WindowXYZVM();
                WindowXYZ = new WindowXYZ();
                WindowMonitorVM = new WindowMonitorVM();
                Monitor = new WindowMonitor();
                WindowSlice = new WindowSlice();
                WindowOtherVM = new WindowOtherVM();
                WindowLayer = new WindowLayer();
                SliceParaVM = new SliceParaVM();
                LogHelper = new LogHelper(DateTime.Now.ToString("yy-MM-dd") + "_log.txt");
                WindowImportGCode = new WindowImportGCode();
                gCodeVM = new WindowImportGCodeVM();
                HistoryVM = new WindowCommandHistoryVM();
                printParaVM = new PrintParaVM();
                Global.LogHelper.WriteLog("3DPrinterSoftware Init");
            }
            catch (Exception ex)
            {
                // 记录异常信息
                Console.Error.WriteLine($"Global静态构造函数异常: {ex}");
                throw;
            }
        }
    }
}
